home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk6 / enough / enough.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  1KB  |  48 lines

  1. /**************
  2. *
  3. * Enough.c - Tests for the presence of a specified amount of free total ram and
  4. *            free chip ram.
  5. *
  6. * Synopsis - enough TOTAL [CHIP]
  7. *
  8. * Returns  - 0 if enough total ram and chip ram is available.
  9. *            10 (AmigaDOS ERROR level) if enough total ram or chip ram is not
  10. *               available.
  11. *
  12. * Author   - Eric Kennedy           ejkst@cisunx.edu
  13. *
  14. * Status   - public domain
  15. *
  16. **************/
  17.  
  18. #include <exec/memory.h>
  19.  
  20. main(argc,argv)
  21. char *argv[];
  22. {
  23.   long freechip, freefast;
  24.   extern long AvailMem();
  25.   long reqchip = 0L;
  26.   long reqtot;
  27.   extern long atol();
  28.  
  29.   if(argc>1)                           /* Is there a first argument? */
  30.   {
  31.     reqtot = atol(argv[1]);
  32.     if(argc > 2)                       /* Is there a second argument? */
  33.       reqchip = atol(argv[2]);
  34.   }
  35.   else
  36.     exit(20);                          /* no error message--keep it small */
  37.  
  38.   Forbid();                            /* get available memory */
  39.   freechip = AvailMem (MEMF_CHIP);
  40.   freefast = AvailMem (MEMF_FAST);
  41.   Permit();
  42.                                        /* compare to requested mem */
  43.   if((freechip >= reqchip) && (freechip+freefast >= reqtot))
  44.     exit(0);                           /* there was enough */
  45.   else
  46.     exit(10);                          /* there wasn't enough */
  47. }
  48.